package com.ruoyi.hospital.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.hospital.domain.YlPackage;
import com.ruoyi.hospital.service.IYlPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 套餐信息Controller
 * 
 * @author ruoyi
 * @date 2022-02-16
 */
@RestController
@RequestMapping("/package")
public class YlPackageController extends BaseController
{
    @Autowired
    private IYlPackageService ylPackageService;

    /**
     * 查询套餐信息列表
     */
    @RequiresPermissions("hospital:package:list")
    @GetMapping("/list")
    public TableDataInfo list(YlPackage ylPackage)
    {
        startPage();
        List<YlPackage> list = ylPackageService.selectYlPackageList(ylPackage);
        return getDataTable(list);
    }

    /**
     * 导出套餐信息列表
     */
    @RequiresPermissions("hospital:package:export")
    @Log(title = "套餐信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YlPackage ylPackage)
    {
        List<YlPackage> list = ylPackageService.selectYlPackageList(ylPackage);
        ExcelUtil<YlPackage> util = new ExcelUtil<YlPackage>(YlPackage.class);
        util.exportExcel(response, list, "套餐信息数据");
    }

    /**
     * 获取套餐信息详细信息
     */
    @RequiresPermissions("hospital:package:query")
    @GetMapping(value = "/{packageId}")
    public AjaxResult getInfo(@PathVariable("packageId") Long packageId)
    {
        return AjaxResult.success(ylPackageService.selectYlPackageByPackageId(packageId));
    }

    /**
     * 新增套餐信息
     */
    @RequiresPermissions("hospital:package:add")
    @Log(title = "套餐信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YlPackage ylPackage)
    {
        return toAjax(ylPackageService.insertYlPackage(ylPackage));
    }

    /**
     * 修改套餐信息
     */
    @RequiresPermissions("hospital:package:edit")
    @Log(title = "套餐信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YlPackage ylPackage)
    {
        return toAjax(ylPackageService.updateYlPackage(ylPackage));
    }

    /**
     * 删除套餐信息
     */
    @RequiresPermissions("hospital:package:remove")
    @Log(title = "套餐信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packageIds}")
    public AjaxResult remove(@PathVariable Long[] packageIds)
    {
        return toAjax(ylPackageService.deleteYlPackageByPackageIds(packageIds));
    }
}
